﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace Assets.Scripts.DynamicClouds
{
	// Token: 0x02000289 RID: 649
	public class CloudController : MonoBehaviour
	{
		// Token: 0x06000E4F RID: 3663 RVA: 0x0006EA53 File Offset: 0x0006CC53
		private void Awake()
		{
			GameController.cloudController = base.gameObject.GetComponent<CloudController>();
		}

		// Token: 0x06000E50 RID: 3664 RVA: 0x0006EA68 File Offset: 0x0006CC68
		private void Update()
		{
			if (this.CloudCompression != this.mPrevCloudCompressionState)
			{
				Physics.IgnoreLayerCollision(21, 21, !this.CloudCompression);
				this.mPrevCloudCompressionState = this.CloudCompression;
			}
			if (this.Populate)
			{
				this.SpawnClouds();
				this.Populate = false;
			}
			if (this.WipeClouds)
			{
				foreach (CloudHub cloudHub in this.CloudHubs)
				{
					UnityEngine.Object.Destroy(cloudHub.gameObject);
				}
				this.CloudHubs.Clear();
				this.WipeClouds = false;
			}
			if (this.SimpleClouds != null)
			{
				if (!this.UseSimpleClouds && this.SimpleClouds.activeInHierarchy)
				{
					this.SimpleClouds.SetActive(false);
				}
				else if (this.UseSimpleClouds && !this.SimpleClouds.activeInHierarchy)
				{
					this.SimpleClouds.SetActive(true);
				}
			}
		}

		// Token: 0x06000E51 RID: 3665 RVA: 0x0006EB90 File Offset: 0x0006CD90
		private void PlaceCloudHub(Vector3 position)
		{
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.CloudHubPreFab, position, base.transform.localRotation);
			gameObject.transform.position = position;
			CloudHub component = gameObject.GetComponent<CloudHub>();
			this.CloudHubs.Add(component);
		}

		// Token: 0x06000E52 RID: 3666 RVA: 0x0006EBD4 File Offset: 0x0006CDD4
		public void SpawnClouds()
		{
			Vector3 position = new Vector3(GameController.playerInstance.gameObject.transform.position.x, GameController.playerInstance.gameObject.transform.position.y + this.CloudAltitude * this.CloudScale, GameController.playerInstance.gameObject.transform.position.z);
			float num = (float)this.CloudSpawnAreaRandomX * this.CloudScale * 2f;
			float num2 = (float)this.CloudSpawnAreaRandomZ * this.CloudScale * 2f;
			this.mIterationZ = this.CloudHubSpawnRange * -1;
			if (this.CloudHubSpawnRange < 1)
			{
				this.PlaceCloudHub(position);
			}
			else
			{
				while (this.mIterationZ < this.CloudHubSpawnRange)
				{
					this.mIterationX = this.CloudHubSpawnRange * -1;
					while (this.mIterationX < this.CloudHubSpawnRange)
					{
						if (UnityEngine.Random.Range(this.SkyFill, 11) == 10)
						{
							this.PlaceCloudHub(new Vector3(position.x + num * (float)this.mIterationX, position.y, position.z + num2 * (float)this.mIterationZ));
						}
						this.mIterationX++;
					}
					this.mIterationZ++;
					this.mIterationX = this.CloudHubSpawnRange * -1;
				}
				this.mIterationZ = this.CloudHubSpawnRange * -1;
			}
			foreach (CloudHub cloudHub in this.CloudHubs)
			{
				cloudHub.GenerateCumulous();
			}
		}

		// Token: 0x04001330 RID: 4912
		public GameObject SimpleClouds;

		// Token: 0x04001331 RID: 4913
		public GameObject CloudHubPreFab;

		// Token: 0x04001332 RID: 4914
		public bool UseSimpleClouds;

		// Token: 0x04001333 RID: 4915
		[Range(0f, 20f)]
		public float CloudAltitude;

		// Token: 0x04001334 RID: 4916
		public bool Overcast;

		// Token: 0x04001335 RID: 4917
		[Range(5f, 50f)]
		public int CloudSpawnAreaRandomX;

		// Token: 0x04001336 RID: 4918
		[Range(5f, 50f)]
		public int CloudSpawnAreaRandomZ;

		// Token: 0x04001337 RID: 4919
		[Range(1f, 10f)]
		public int CloudSpawnAreaRandomHieght;

		// Token: 0x04001338 RID: 4920
		[Range(0f, 100f)]
		public int CloudSpawnAreaRandomFillPercent;

		// Token: 0x04001339 RID: 4921
		[Range(5f, 30f)]
		public int CloudSpawnAreaRandomReductionFactorPerLayer;

		// Token: 0x0400133A RID: 4922
		[Range(1f, 40000f)]
		public float CloudScale;

		// Token: 0x0400133B RID: 4923
		public List<CloudHub> CloudHubs = new List<CloudHub>();

		// Token: 0x0400133C RID: 4924
		[Range(0f, 200000f)]
		public float CloudGtsActivationRange;

		// Token: 0x0400133D RID: 4925
		[Range(0f, 200000f)]
		public float CloudPlayerActivationRange;

		// Token: 0x0400133E RID: 4926
		public bool CloudSleepingByCoroutine;

		// Token: 0x0400133F RID: 4927
		public bool ActiveShadows;

		// Token: 0x04001340 RID: 4928
		[Range(1f, 1000f)]
		public int CloudPhysicsWakeSleepPerFrame;

		// Token: 0x04001341 RID: 4929
		[HideInInspector]
		public int ChangedPhysicsStates;

		// Token: 0x04001342 RID: 4930
		[Range(1f, 1000f)]
		public int CloudShadowsCheckedPerFrame;

		// Token: 0x04001343 RID: 4931
		[HideInInspector]
		public int CheckedShadows;

		// Token: 0x04001344 RID: 4932
		[Range(1f, 1000f)]
		public int CloudLODAdjustmentsPerFrame;

		// Token: 0x04001345 RID: 4933
		[HideInInspector]
		public int SetLODs;

		// Token: 0x04001346 RID: 4934
		public bool CloudPhysics;

		// Token: 0x04001347 RID: 4935
		public bool CloudCompression;

		// Token: 0x04001348 RID: 4936
		private bool mPrevCloudCompressionState;

		// Token: 0x04001349 RID: 4937
		public bool DisableCloudElastisity;

		// Token: 0x0400134A RID: 4938
		public bool LimitCloudpush;

		// Token: 0x0400134B RID: 4939
		[Range(0.002f, 0.2f)]
		public float CloudElastisityFactor;

		// Token: 0x0400134C RID: 4940
		[Range(0.1f, 100f)]
		public float CloudElastisityPositionTolerence;

		// Token: 0x0400134D RID: 4941
		[Range(0.01f, 100f)]
		public float CloudElastisityPositionMaxLimit;

		// Token: 0x0400134E RID: 4942
		public bool LockCloudTileElevation;

		// Token: 0x0400134F RID: 4943
		public bool LockCloudTileRotation;

		// Token: 0x04001350 RID: 4944
		[Range(1f, 7f)]
		public float GtsAirComressionFactor;

		// Token: 0x04001351 RID: 4945
		public bool CloudLODEnabled;

		// Token: 0x04001352 RID: 4946
		[Range(1500f, 150000f)]
		public float MidDistanceLOD;

		// Token: 0x04001353 RID: 4947
		[Range(1f, 10f)]
		public int SkyFill;

		// Token: 0x04001354 RID: 4948
		[Range(0f, 5f)]
		public int CloudHubSpawnRange;

		// Token: 0x04001355 RID: 4949
		private int mIterationX;

		// Token: 0x04001356 RID: 4950
		private int mIterationZ;

		// Token: 0x04001357 RID: 4951
		public bool BeingInShadowRangeOverridesPhysics;

		// Token: 0x04001358 RID: 4952
		public bool PlayerProximityCanActivateShadowChecks;

		// Token: 0x04001359 RID: 4953
		public bool UseTestVisuals;

		// Token: 0x0400135A RID: 4954
		public bool Populate;

		// Token: 0x0400135B RID: 4955
		public bool WipeClouds;
	}
}
